
#1)利用session发送登录请求
import requests
url_login='https://gitee.com/login'
#user_agent请求头
headers={'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'}
#请求集体数据
data={
    'encrypt_key': 'password',
    'utf8': '✓',
    'authenticity_token': 'umYUQPNNM8BF+gYCfCUKJ0lOu5bR9qESHE+f2g1Z5UQ=',
    'redirect_to_url': '',
    'user[login]': '2760057963@qq.com',
    'encrypt_data[user[password]]': 'Jyk7eYiJCUrXwES4gplUHAX1eo+N8ZByFRjHWUvN8cOh7wf3ezSU5BJDJZVgFDIkC0QmQiw8lKJ2UTfeu6m5yLID0MSWeGuz9LZEZGlZvKwaqcYtTgXArI2k1RHZPT0Gh4lsdarbVsd95ezVoX0v6ARuOlZ6mRC5jl9dYyuX3is=',
    'user[remember_me]': '0'
}
#用session来发送登录请求，可以实现状态保持
session=requests.session()
r=session.post(url_login,headers=headers,data=data)
print(r.status_code)
print(r.content.decode())

#2)利用session发送 登录后才能访问的页面 不要要加cookie  session实现状态保持
url='https://gitee.com/guotongda/dashboard/projects'
r2=session.get(url,headers=headers)
print(r2.content.decode())
